﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using MakeIT.MiraPark.Negocios;
using Microsoft.VisualBasic.PowerPacks;

namespace MiraPark
{
    public partial class FormMaisSelect : Form
    {
        public FormMaisSelect()
        {
            InitializeComponent();
        }

        private void FormMaisSelect_Load(object sender, EventArgs e)
        {
            vScrollBar1.Minimum = this.flowLayoutPanelMais.VerticalScroll.Minimum;
            vScrollBar1.Maximum = this.flowLayoutPanelMais.VerticalScroll.Maximum;//modelos.Count + 3;
            vScrollBar1.LargeChange = this.flowLayoutPanelMais.VerticalScroll.LargeChange;
            vScrollBar1.SmallChange = this.flowLayoutPanelMais.VerticalScroll.SmallChange;
            vScrollBar1.Value = this.flowLayoutPanelMais.VerticalScroll.Value;

        }

        public void MaisCores(EventHandler eventHandler)
        {
            List<CorVO> cores = ModelBO.getCores();

            int precedencia = -1;
            this.flowLayoutPanelMais.Controls.Clear();

            foreach (CorVO cor in cores)
            {
                if (precedencia != cor.ordem)
                {
                    if (precedencia > 0)
                    {
                        Button mybuttonLix = new Button();
                        mybuttonLix.Size = new System.Drawing.Size(634, 8);
                        flowLayoutPanelMais.Controls.Add(mybuttonLix);
                    }
                    precedencia = cor.ordem;
                }
                
                Button mybutton = new Button();
                mybutton.BackColor = System.Drawing.Color.FromArgb(cor.a, cor.r, cor.g, cor.b);
                if (cor.r + cor.g + cor.b < 257)
                    mybutton.ForeColor = System.Drawing.Color.FromArgb(255, 255, 255, 255);
                mybutton.Font = new System.Drawing.Font("Verdana", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                mybutton.Name = "button" + cor.nome.Trim();
                mybutton.Size = new System.Drawing.Size(122, 51);
                mybutton.TabIndex = 14;
                mybutton.Text = cor.nome.ToUpper().Trim();
                mybutton.UseVisualStyleBackColor = false;
                mybutton.Click += eventHandler + new EventHandler(this.buttonFecharJanelaMais_Click);
                mybutton.Tag = cor;

                flowLayoutPanelMais.Controls.Add(mybutton);

            }
            groupBoxMais.Text = " Cores: ";

        }
        public void MaisTipoVeiculos(EventHandler eventHandler)
        {
            List<TipoVeiculoVO> tipoVeiculos = ModelBO.getTipoVeiculos(true, null);

            int precedencia = -1;
            this.flowLayoutPanelMais.Controls.Clear();

            foreach (TipoVeiculoVO tipoVeiculo in tipoVeiculos)
            {
                if (precedencia != tipoVeiculo.ordem)
                {
                    if (precedencia > 0)
                    {
                        Button mybuttonLix = new Button();
                        mybuttonLix.Size = new System.Drawing.Size(634, 8);
                        flowLayoutPanelMais.Controls.Add(mybuttonLix);
                    }
                    precedencia = tipoVeiculo.ordem;
                }

                Button mybutton = new Button();
                mybutton.Font = new System.Drawing.Font("Verdana", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                mybutton.Name = "button" + tipoVeiculo.tipoVeiculo.Trim();
                mybutton.Size = new System.Drawing.Size(122, 51);
                mybutton.TabIndex = 2;
                mybutton.Text = tipoVeiculo.tipoVeiculo.ToUpper().Trim();
                mybutton.UseVisualStyleBackColor = true;
                mybutton.Click += eventHandler + new EventHandler(this.buttonFecharJanelaMais_Click);
                mybutton.Tag = tipoVeiculo;

                this.flowLayoutPanelMais.Controls.Add(mybutton);

            }
            groupBoxMais.Text = " Tipo de Veículos: ";

        }
        public void MaisMarcas(EventHandler eventHandler, TipoVeiculoVO tipoVeiculoVO)
        {
            List<MarcaVO> marcas = ModelBO.getMarcasByTipoVeiculo(tipoVeiculoVO.idTipoVeiculo);

            int precedencia = -1;
            this.flowLayoutPanelMais.Controls.Clear();

            foreach (MarcaVO marca in marcas)
            {
                if (precedencia != marca.ordem)
                {
                    if (precedencia > 0)
                    {
                        Button mybuttonLix = new Button();
                        mybuttonLix.Size = new System.Drawing.Size(634, 8);
                        flowLayoutPanelMais.Controls.Add(mybuttonLix);
                    }
                    precedencia = marca.ordem;
                }

                Button mybutton = new Button();
                mybutton.Font = new System.Drawing.Font("Verdana", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                mybutton.Name = "button" + marca.marca.Trim();
                mybutton.Size = new System.Drawing.Size(122, 51);
                mybutton.TabIndex = 2;
                mybutton.Text = marca.marca.ToUpper().Trim();
                mybutton.UseVisualStyleBackColor = true;
                mybutton.Click += eventHandler + new EventHandler(this.buttonFecharJanelaMais_Click);
                mybutton.Tag = marca;

                this.flowLayoutPanelMais.Controls.Add(mybutton);
            }
            groupBoxMais.Text = " Marcas: ";

        }
        public void MaisModelos(EventHandler eventHandler, TipoVeiculoVO tipoVeiculoVO)
        {
            List<ModeloVO> modelos = ModelBO.getModelos(false, true, null, null, tipoVeiculoVO, true);

            int precedencia = -1;
            this.flowLayoutPanelMais.Controls.Clear();


            foreach (ModeloVO modelo in modelos)
            {
                if (precedencia != modelo.ordem)
                {
                    if (precedencia > 0)
                    {
                        Button mybuttonLix = new Button();
                        mybuttonLix.Size = new System.Drawing.Size(634, 8);
                        flowLayoutPanelMais.Controls.Add(mybuttonLix);

                    }
                    precedencia = modelo.ordem;
                }

                Button mybutton = new Button();
                mybutton.Font = new System.Drawing.Font("Verdana", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                mybutton.Name = "button" + modelo.modelo.Trim();
                mybutton.Size = new System.Drawing.Size(122, 51);
                mybutton.TabIndex = 2;
                mybutton.Text = modelo.modelo.ToUpper().Trim();
                mybutton.UseVisualStyleBackColor = true;
                mybutton.Click += eventHandler + new EventHandler(this.buttonFecharJanelaMais_Click);
                mybutton.Tag = modelo;

                this.flowLayoutPanelMais.Controls.Add(mybutton);

            }
            groupBoxMais.Text = " Modelos: ";

        }
        public void MaisConvenios(EventHandler eventHandler)
        {
            List<ConvenioVO> convenios = ModelBO.getConvenios(true);

            this.flowLayoutPanelMais.Controls.Clear();
            foreach (ConvenioVO convenio in convenios)
            {
                Button mybutton = new Button();
                mybutton.Font = new System.Drawing.Font("Verdana", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                mybutton.Name = "button" + convenio.clienteVO.nome.Trim();
                mybutton.Size = new System.Drawing.Size(122, 51);
                mybutton.TabIndex = 2;
                mybutton.Text = convenio.clienteVO.nome.ToUpper().Trim();
                mybutton.UseVisualStyleBackColor = true;
                mybutton.Click += eventHandler + new EventHandler(this.buttonFecharJanelaMais_Click);
                mybutton.Tag = convenio;

                this.flowLayoutPanelMais.Controls.Add(mybutton);

            }
            groupBoxMais.Text = " Convênios: ";

        }

        public void MaisFormasPagamento(EventHandler eventHandler)
        {
            List<FormaPagamentoVO> listFormaPagamentoVOs = ModelBO.getFormaPagamentos();

            int precedencia = -1;

            this.flowLayoutPanelMais.Controls.Clear();
            foreach (FormaPagamentoVO formaPagamentoVO in listFormaPagamentoVOs)
            {
                if (precedencia != formaPagamentoVO.ordem)
                {
                    if (precedencia > 0)
                    {
                        Button mybuttonLix = new Button();
                        mybuttonLix.Size = new System.Drawing.Size(634, 8);
                        flowLayoutPanelMais.Controls.Add(mybuttonLix);
                    }
                    precedencia = formaPagamentoVO.ordem;
                }

                Button mybutton = new Button();
                mybutton.Font = new System.Drawing.Font("Verdana", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                mybutton.Name = "button" + formaPagamentoVO.formaPagamento.Trim();
                mybutton.Size = new System.Drawing.Size(122, 51);
                mybutton.TabIndex = 2;
                mybutton.Text = formaPagamentoVO.formaPagamento.ToUpper().Trim();
                mybutton.UseVisualStyleBackColor = true;
                mybutton.Click += eventHandler + new EventHandler(this.buttonFecharJanelaMais_Click);
                mybutton.Tag = formaPagamentoVO;

                this.flowLayoutPanelMais.Controls.Add(mybutton);

            }
            groupBoxMais.Text = " Formas de Pagamento: ";

       }

        private void vScrollBar1_Scroll(object sender, ScrollEventArgs e)
        {
            //flowLayoutPanelMais.ScrollControlIntoView(flowLayoutPanelMais.Controls[e.NewValue]);
            this.flowLayoutPanelMais.VerticalScroll.Value = e.NewValue; //Math.Min(e.NewValue, this.flowLayoutPanelMais.VerticalScroll.Maximum);
        }

        private void buttonFecharJanelaMais_Click(object sender, EventArgs e)
        {
            this.Close();
        }


    }
}
